/*
 * Copyright (C) 2010 M. Hautle.
 * 
 * This file is part of SimpleEL.
 * 
 * SimpleEL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * SimpleEL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with SimpleEL. If not, see <http://www.gnu.org/licenses/>.
 */
package ch.simpleel.data;

import java.util.*;

/**
 * Factory creating and populating the test beans.
 * 
 * @author M. Hautle
 */
public class DataFactory {
    /**
     * Returns a populated {@link CollisionBean}.
     * 
     * @return A bean
     */
    public static CollisionBean createCollisionBean() {
        CollisionBean b = new CollisionBean();
        b.setAkwA("akwa");
        b.setAlXA("alxa");
        b.setBar("bar");
        b.setbLwA("blwa");
        b.setbMXA("bmxa");
        b.setFoo("foo");
        b.setRuEB("rueb");
        b.setsVEB("sveb");
        return b;
    }

    /**
     * Returns a populated {@link ABean}.
     * 
     * @return A bean
     */
    public static ABean createSelfreferencingSimple() {
        final ABean b = populateSimple(new ABean());
        b.setNested(b);
        return b;
    }

    /**
     * Returns a populated {@link ABean}.
     * 
     * @return A bean
     */
    public static ABean createCyclicSimple() {
        final ABean b = populateSimple(new ABean());
        final ABean nested = populateSimple(new ABean());
        b.setNested(nested);
        nested.setNested(b);
        return b;
    }

    /**
     * Returns a populated {@link ABean}.
     * 
     * @return A bean
     */
    public static ABean createSimple() {
        final ABean b = populateSimple(new ABean());
        b.setNested(populateSimple(new ABean()));
        return b;
    }

    /**
     * Returns a populated {@link BBean}.
     * 
     * @return A bean
     */
    public static BBean createExtended() {
        final BBean b = new BBean();
        populateSimple(b);
        b.setNested(populateSimple(new ABean()));
        b.setText("subdi");
        return b;
    }

    /**
     * Creates an populates a {@link PrimitiveTypeBean}.
     * 
     * @return A {@link PrimitiveTypeBean}
     */
    public static PrimitiveTypeBean createPrimitiveBean() {
        final PrimitiveTypeBean b = new PrimitiveTypeBean();
        b.setAge((short) 42);
        b.setArray(new short[] { 0, 2, 4, 8, 16 });
        b.setBig(3.14);
        b.setCheckSum(Long.MAX_VALUE);
        b.setDefined(true);
        b.setFlags((byte) 127);
        b.setLetter('q');
        b.setSaldo(-13);
        b.setValue(512);
        return b;
    }

    /**
     * Populates a {@link ABean}.
     * 
     * @param b The bean
     * @return The bean
     */
    private static ABean populateSimple(final ABean b) {
        b.setAge((short) 10);
        b.setArray(new short[] { 5, 6, 7 });
        b.setBig(1.5);
        b.setCheckSum(25l);
        b.setDefined(true);
        b.setFlags((byte) 15);
        b.setLetter('q');
        b.setName("foo");
        b.setSaldo(1.5f);
        b.setValue(42);
        b.setDate(new Date());
        try {
            b.setExceptional("exception :)");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b;
    }
}
